Skip to content

Add test for flatbuffers array header - #437

Open
paulquiring wants to merge 2 commits into
eclipse-score:mainfrom
etas-contrib:paulquiring/add_flatbuffers_array_test
Open

Add test for flatbuffers array header#437
paulquiring wants to merge 2 commits into
eclipse-score:mainfrom
etas-contrib:paulquiring/add_flatbuffers_array_test

Conversation

@paulquiring

@paulquiring paulquiring commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Add test for flatbuffers/array.h.

@github-project-automation github-project-automation Bot moved this to In Progress in BAS - Baselibs FT Jul 31, 2026
@paulquiring
paulquiring temporarily deployed to workflow-approval July 31, 2026 12:07 — with GitHub Actions Inactive
@paulquiring
paulquiring temporarily deployed to workflow-approval July 31, 2026 12:07 — with GitHub Actions Inactive
@paulquiring
paulquiring temporarily deployed to workflow-approval July 31, 2026 12:07 — with GitHub Actions Inactive
@paulquiring
paulquiring temporarily deployed to workflow-approval July 31, 2026 12:07 — with GitHub Actions Inactive
@github-actions github-actions Bot added comp-flatbuffers Related to score/flatbuffers component c++ C++ code bazel Bazel and Starlark build files labels Jul 31, 2026
@paulquiring paulquiring changed the title Add test for flatbuffers/array.h Add test for flatbuffers array header Jul 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The created documentation from the pull request is available at: docu-html

@paulquiring paulquiring self-assigned this Jul 31, 2026
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds GoogleTest coverage for the upstream FlatBuffers C++ headers used by score/flatbuffers, specifically targeting flatbuffers/array.h and flatbuffers/allocator.h, and wires the new tests into the Bazel cc_test target.

Changes:

  • Add comprehensive unit/fault-injection tests for flatbuffers/array.h APIs and specializations.
  • Add interface/fault-injection tests for flatbuffers/allocator.h, including Allocator::reallocate_downward.
  • Fix and expand score/flatbuffers:flatbuffers_cpp_library_test sources in score/flatbuffers/BUILD.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
score/flatbuffers/details/flatbuffers_array_test.cpp New test suite covering flatbuffers::Array behaviors (casts, iteration, spans, mutation, CopyFromSpan, specialization/death tests).
score/flatbuffers/details/flatbuffers_allocator_test.cpp New test suite validating flatbuffers::Allocator contract and default reallocate_downward behavior (including fault paths).
score/flatbuffers/BUILD Updates flatbuffers_cpp_library_test to use the correct allocator test filename and adds the new array tests.
Suppressed comments (3)

score/flatbuffers/details/flatbuffers_array_test.cpp:664

  • This downcast is undefined behavior: CastToArray(raw) does not produce an ArrayTestAccess<T,N> object, so static_casting the base reference to the derived type is invalid. Use an explicit reinterpret_cast overlay if you need to call the protected overloads.
    auto& accessor = static_cast<ArrayTestAccess<int32_t, 3>&>(CastToArray(raw));

score/flatbuffers/details/flatbuffers_array_test.cpp:683

  • This downcast is undefined behavior: CastToArray(raw) does not produce an ArrayTestAccess<T,N> object, so static_casting the base reference to the derived type is invalid. Use an explicit reinterpret_cast overlay if you need to call the protected overloads.
    auto& accessor = static_cast<ArrayTestAccess<Point, 2>&>(CastToArray(raw));

score/flatbuffers/details/flatbuffers_array_test.cpp:756

  • This reinterpret_cast assumes the byte buffer is suitably aligned (and large enough) for Array<Offset, 2>. Use alignas + sizeof(Array<...>) to avoid misalignment/size-related UB.
    uint8_t buf[2] = {0};
    const auto& arr = *reinterpret_cast<const Array<Offset<void>, 2>*>(buf);
    EXPECT_DEATH({ arr[0]; }, "");

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
@paulquiring
paulquiring force-pushed the paulquiring/add_flatbuffers_array_test branch from 35ebbe4 to ffa0e6e Compare August 4, 2026 10:09
@paulquiring
paulquiring force-pushed the paulquiring/add_flatbuffers_array_test branch from ffa0e6e to d16d6a5 Compare August 4, 2026 11:16
Comment thread score/flatbuffers/details/flatbuffers_array_test.cpp Outdated
@paulquiring
paulquiring force-pushed the paulquiring/add_flatbuffers_array_test branch from 19633fe to dbbd577 Compare August 4, 2026 13:28
@paulquiring
paulquiring force-pushed the paulquiring/add_flatbuffers_array_test branch from dbbd577 to 73860ec Compare August 4, 2026 13:54
MaciejKaszynski
MaciejKaszynski previously approved these changes Aug 4, 2026
@paulquiring
paulquiring force-pushed the paulquiring/add_flatbuffers_array_test branch from 15f5bcf to f5737c8 Compare August 5, 2026 08:02
@paulquiring
paulquiring temporarily deployed to workflow-approval August 5, 2026 08:02 — with GitHub Actions Inactive
@paulquiring
paulquiring temporarily deployed to workflow-approval August 5, 2026 08:02 — with GitHub Actions Inactive
@paulquiring
paulquiring temporarily deployed to workflow-approval August 5, 2026 08:02 — with GitHub Actions Inactive
@paulquiring
paulquiring temporarily deployed to workflow-approval August 5, 2026 08:02 — with GitHub Actions Inactive

TEST(ArrayCastTest, CastToArray)
{
RecordProperty("FullyVerifies", "::flatbuffers::CastToArray");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of linking is not acceptable by the process and gets rejected by docs-as-code. It should be a sphinx-needs element, preferably a requirement.

I'm trying to fix some of the flatbuffers tests here: #469

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel Bazel and Starlark build files c++ C++ code comp-flatbuffers Related to score/flatbuffers component

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants